package network;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientEcho {

	public static void main(String[] args) throws UnknownHostException,
			IOException {
		int port = 2501;
		
		Socket socket = new Socket(InetAddress.getLocalHost(), port);

		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(
					socket.getInputStream()));
			PrintWriter out = new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(socket.getOutputStream())), true);
			
			for (int i = 0; i < 10; i++) {
				out.println(">> to server : " + i);
				String str = in.readLine();
				System.out.println("from server >> " + str);
			}
			out.println("END");
		} finally {
			socket.close();
		}
	}
}
